import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:get/get.dart';
import 'package:happy_study/ui/login/login_view.dart';
import 'package:happy_study/ui/shared/app_theme.dart';

import 'core/router/router.dart';
import 'core/shared_preference/shared_preference_util.dart';

void main() async{
  await ScreenUtil.ensureScreenSize();
  await SharedPreferenceUtil.getInstance();
  await initApp();
  runApp(const MyApp());
}

Future<void> initApp() async{
  WidgetsFlutterBinding.ensureInitialized();
  SystemChrome.setPreferredOrientations(
      [DeviceOrientation.landscapeLeft, DeviceOrientation.landscapeRight]);
  SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual, overlays: []);
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return ScreenUtilInit(
      minTextAdapt: true,
      splitScreenMode: true,
      designSize: const Size(360, 690),
      builder: (ctx, child) {
        return GetMaterialApp(
          debugShowCheckedModeBanner: false,
          theme: HYAppTheme.norTheme,
          title: 'Happy Study',
          initialRoute: HYRouter.initialRoute,
          getPages: HYRouter.getPages,
          navigatorObservers: [FlutterSmartDialog.observer],
          builder: FlutterSmartDialog.init(),
        );
      },
    );
  }
}
